#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<int> arr(100, 0);
    arr[1] = 1;
    int n = 0;
    cin >> n;
    int i = 2;
    while (n >= arr[i-1])
    {
        if (i > 1)
        {
            arr[i] = arr[i - 1] + arr[i - 2];
        }
        i++;
    }
    i--;
    
    int ret = min(arr[i] - n, n - arr[i - 1]);
    cout << ret;


}